package com.server.jaxrs;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import java.util.UUID;

import com.server.ejb.UserBean;
import com.server.entity.*;


@Stateless
@Path("User")
public class UserAPI {
	
	@EJB
	private UserBean ub;
	
    @Context
    private UriInfo context;

    /**
     * Default constructor. 
     */
    public UserAPI() {
        // TODO Auto-generated constructor stub
    }

    /**
     * Retrieves representation of an instance of UserAPI
     * @return an instance of String
     */
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("{Name}/{AccountType}")
    public String registerUser(@PathParam("Name") String name,@PathParam("AccountType") String type) {
        // TODO return proper representation object
    	User user= new User(UUID.randomUUID().toString(),name);
    	Account ac = new Account(UUID.randomUUID().toString(),user.getUserId().toString());
    	if(ub.RegisterUser(user,ac)){
    		return "Register Succeed!";
    	}
    	else return "Register Failed!";
    }

    /**
     * PUT method for updating or creating an instance of UserAPI
     * @param content representation for the resource
     * @return an HTTP response with content of the updated or created resource.
     */
    @PUT
    @Consumes("application/xml")
    public void putXml(String content) {
    }

}